﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Homework2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_KeyDown(object sender, KeyEventArgs e)

        {

            if (e.KeyCode == Keys.Enter)//判断回车键

            {

                this.button1_Click(sender, e);//触发按钮事件

            }

        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                double a = double.Parse(this.textBox1.Text);
                double b = double.Parse(this.textBox2.Text);
                string c = this.comboBox1.Text;
                if (c == "+")
                {
                    this.textBox3.Text = (a + b).ToString();
                }
                else if (c == "-")
                {
                    this.textBox3.Text = (a - b).ToString();
                }
                else if (c == "*")
                {
                    this.textBox3.Text = (a * b).ToString();
                }
                else if (c == "/")
                {
                    this.textBox3.Text = (a / b).ToString();
                }
                else
                {
                    this.textBox3.Text = "ERROR!";
                }
            }
            catch (Exception)
            {
                this.textBox3.Text = "ERROR!";
            }
            
        }
    }
}
